package com.citrinus.feedme.list;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.citrinus.feedme.App;
import com.citrinus.feedme.R;
import com.citrinus.feedme.places.Place;

public class RestaurantsListAdapter extends ArrayAdapter<Place> {

	private List<Place> places;
	private ViewHolder holder;
	private LayoutInflater inflater;
	private int row;
	

	public RestaurantsListAdapter(Context context, int row, List<Place> places) {
		super(context, row, places);
		this.places = places;
		this.inflater = LayoutInflater.from(context);
		this.row = row;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Place place = places.get(position);
		holder = null;

		if (convertView == null) {
			convertView =  inflater.inflate(row, null);
			holder = new ViewHolder();
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.title = (TextView) convertView.findViewById(R.id.title);
		holder.title.setText(place.getName());
		holder.title.setTypeface(App.getRobot());
		
		holder.subtitle = (TextView) convertView.findViewById(R.id.subtitle);
		holder.subtitle.setText(place.getVicinity());
		holder.subtitle.setTypeface(App.getRobot());
		
		holder.distance = (TextView) convertView.findViewById(R.id.distance);
		holder.distance.setTypeface(App.getRobotBold());
		holder.distance.setText(place.getDistanceInYards());
	
		return convertView;
	}

	private static class ViewHolder {
		TextView distance;
		TextView title;
		TextView subtitle;
	}

}
